//用于存放关键词的数组
var keyworldArray = []

var existed;

//定义变量用于接受layui的组件
var form;
var element;
var laydate;
var layer;
//当前窗口索引
var currentIndex;

layui.use(['form', 'layer', 'laydate', 'table', 'laytpl', 'element'], function () {
    element = layui.element;
    laydate = layui.laydate;
    layer = layui.layer
    form = layui.form;
    currentIndex = parent.layer.getFrameIndex(window.name);//获取当前窗体索引


    //监听编辑问题还是添加问题下拉框
    form.on("select(quesetionType)", function (data) {

        //清空隐藏title,是校验模式切换
        $("#originalTitle").val("");

        //切换到添加问题
        if (data.value == "1") {

            //清空数据
            resetToAdd();
            //选择问题框要清空
            $("#chooseKnowledgeBaseId").val("");
            $("#chooseKnowledgeText").val("");
            $("#quesetionType").val("1");
            //下拉框选择添加问题
            $("#needSelect").css("display", "block");
            // 隐藏问题选择框
            $("#selectKnowledgeBase").css("display", "none");
            //隐藏原话术包div
            $("#packageDiv").css("display","none")
            //添加标准答案显现
            $("#oneToOneanswer").css("display","block");
            //验证显现
            oneToOneVerify();
            //更新渲染
            form.render();

        } else {

            //清空数据
            resetToAdd();
            //选择问题框要清空
            $("#chooseKnowledgeBaseId").val("");
            $("#chooseKnowledgeText").val("");
            $("#quesetionType").val("0");
            //下拉框选择添加问题
            $("#selectKnowledgeBase").css("display", "block");
            $("#needSelect").css("display", "none");
            //显示原话术包div
            $("#packageDiv").css("display","block")
            //更新渲染
            form.render();

        }

    })


    //监听radio单选项,选择单句问答,或者多句问答
    form.on('radio(radioAnswerType)', function (data) {

        //切换到单选
        if (data.value == "ONE_TO_ONE") {

            //隐藏多选
            $("#multiSelectAnswerType").css("display", "none");
            //显示加标准答案
            $("#oneToOneanswer").css("display", "block");
            //假如有添加答案,显示
            if ($(".allAnswerDiv").length > 0) {

                //显示问题答案
                $(".allAnswerDiv").css("display", "block")
                //显示回答后操作
                $("#answerAfter").css("display", "block");
                //假如选的是转跳到指定流程显示
                if ($("#answerOperation").val() == "ASSIGN") {
                    //显示答后操作流程
                    $("#selectAnswerType").css("display", "block");
                }

            }

            //取消多轮问答流程验证
            $("#mutiSessionText").attr("lay-verify", "");
            //添加单轮问答验证
            $("#ontoOneText").attr("lay-verify", "mustNoNull")
            //添加单人答案框验证
            $(".allAnswers").attr("lay-verify", "required");
            //假如用户选择的是转跳到指定流程,添加验证
            if ($("#answerOperation").val() == "ASSIGN") {


                $("#skipFlowText").attr("lay-verify", "FlowIdNotNull");
            }

        } else {//切换到多选

            //隐藏加标准答案
            $("#oneToOneanswer").css("display", "none");
            //隐藏回答后操作
            $("#answerAfter").css("display", "none");
            //隐藏答后操作流程
            $("#selectAnswerType").css("display", "none");
            //隐藏问题答案
            $(".allAnswerDiv").css("display", "none")
            //显示多选流程选择
            $("#multiSelectAnswerType").css("display", "block");


            //取消单轮答案验证
            $("#ontoOneText").attr("lay-verify", "")

            //取消单人选择流程验证
            $("#skipFlowText").attr("lay-verify", "");

            //取消单人问答答案框验证
            $(".allAnswers").attr("lay-verify", "");

            //添加多轮问答流程验证
            $("#mutiSessionText").attr("lay-verify", "mutiSessionFlowIdNotNull");

        }
    });


    //监听单句问答答后操作的select框
    form.on('select(answerOperation)', function (data) {

        //如果用户选择转跳到指定流程,隐藏的单句流程选框显现
        if (data.value == "ASSIGN") {

            //显示选择流程框
            $("#selectAnswerType").css("display", "block")
            //添加验证
            $("#skipFlowText").attr("lay-verify", "FlowIdNotNull")

        } else {

            $("#selectAnswerType").css("display", "none")
            //取消验证
            $("#skipFlowText").attr("lay-verify", "")

        }

        form.render("select");
    });


    //点击layui的button,触发表单提交
    form.on('submit(addKnowledgeBase)', function (data) {

        console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
        insertDoc(data.field, 'insertOrUpdate', currentIndex);

    });

    //正则表达式用于表单校验
    form.verify({
        //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]

        //校验标题是否存在
        alreadyExisted: function (value, item) {

            //假如隐藏标题不为空,说明是编辑已有问题,需要对比原有标题
            if ($("#originalTitle").val() != null && $("#originalTitle").val() != "") {

                if (value != $("#originalTitle").val()) {

                    //调用方法ajax校验
                    checkTitle(value);
                }else{

                    existed=false;
                }

            } else {
                //调用方法ajax校验
                checkTitle(value);

            }

            if (existed) {

                return "很抱歉标题已经存在";
            }
        },


        //验证单人流程
        FlowIdNotNull: function (value, item) {


            if ($("#skipFlowId").val() == null || $("#skipFlowId").val() == "") {

                return "必须选择流程";
            }

        },
        //验证多轮会话流程
        mutiSessionFlowIdNotNull: function (value, item) {


            if ($("#mutiSessionFlowId").val() == null || $("#mutiSessionFlowId").val() == "") {

                return "必须选择流程";
            }

        },

        mustNoNull: function (value, item) {

            if (value == null || value.trim() == "") {

                return "请添加标准答案"
            }

        },
        title:function(value,item){

            /*if (value.length>20) {

                return "标题长度不能超过12"
            }*/

        },
       /* textarea: [/^[\n\u4E00-\u9FA5A-Za-z0-9,，。.？！?!、]+$/
            , "不能出现非法字符"
        ]*/
        textarea:function (value,item) {
            var questionflag = false;//用来标记校验结果
            $.ajax({
                type: "post",
                url: "/linkcall/knowledgeBase/checkTheHowQuestion",
                data: {"howAskQuestions": $("#questions").val(), "packageId": $("#packageId").val(),"id":$("#chooseKnowledgeBaseId").val()},
                dataType: "json",
                async: false,
                success: function (callBackData) {

                    if (callBackData.total > 0) {

                        var questions = $("#questions").val();

                        var questionslist=questions.split(/["\n"]+/);

                        for (var i in callBackData.records) {

                            if(questionslist.indexOf(callBackData.records[i])!=-1){

                                questionslist.splice(questionslist.indexOf(callBackData.records[i]),1);
                            }
                        }

                        questions=questionslist.join("\n").trim();

                        $("#questions").val(questions);

                        questionflag = true;

                    }
                },
                error: function (callBackData) {

                }
            })

            if (questionflag) {

                return "同一话术包下不能有相同问法,已为你删除"
            }
        }
    });


    //窗体加载完毕,事件触发
    $(function () {

        $("#correction").val(parent.questionValue)

        //赋值给隐藏的id
        $("#questionBaseId").val(parent.questionId);

        //赋值给隐藏的packageId
        $("#packageId").val(parent.packageId);

        //从父页面那里获取到变量
        var selectLearnTypeValue = parent.selectLearnTypeValue

        //赋值给select
        $("#quesetionType").val(selectLearnTypeValue);

        //假如是编辑已有问题
        if (selectLearnTypeValue == '0') {//选择问题显现

            $("#selectKnowledgeBase").css("display", "block");

        } else {

            $("#needSelect").css("display", "block")

        }

        form.render();


    })

});
//自杀事件删除关键词小图标
function GotoDeath(needDeath) {

    //获取jq的DOM对象
    var addKeyword = $(needDeath);

    //取得内容
    var content = addKeyword.val().substring(0, addKeyword.val().length - 2);

    //取得所在数组的索引
    var deleteIndex = keyworldArray.indexOf(content);

    //假如索引不为空,删
    if (deleteIndex != null) {

        keyworldArray.splice(deleteIndex, 1);
    }

    $("#needKeywords").val(keyworldArray.join(","));


    addKeyword.remove();
}


//选择问题改变,重新加载数据回显
function changeKnowledgeBase(label, value) {


    //获取选择Id
    var knowledgeBaseId = value;

//判断
    if (knowledgeBaseId != null && knowledgeBaseId != "") {

        //重置数据
        resetToAdd();

        //清空关键词小图标和问题答案
        $(".displayKeyword").remove();
        $(".allAnswerDiv").remove();

        //发送阿贾克斯请求,查找需要的KnowledgeBase
        $.ajax({
            type: "get",
            data: {id: knowledgeBaseId},
            url: "/linkcall/knowledgeBase/selectById",
            dataType: "json",
            success: function (callbackData) {

                //赋值给隐藏标题
                $("#originalTitle").val(callbackData.title);

                //问题类型
                if (callbackData.knowledgeType == "COMMON") {
                    $("#common").attr("checked", "checked");
                } else {
                    $("#business").attr("checked", "checked");
                }

                $("#originalPackageId").val(callbackData.packageId)
                //根据所属话术包id调用方法再次发送ajax,取得话术包的名字
                findSelectParamName("/linkcall/learningAnalysis/findSpeakingPackage",callbackData.packageId, $("#packageText"),"packageName");

                //问题标题
                $("#title").val(callbackData.title);


                //将关键词list拼成字符串
                $("#needKeywords").val(callbackData.keyworlds.join(","));

                //将关键词存入数组
                if ($("#needKeywords").val().length > 0) {

                    //将关键词分割为数组
                    keyworldArray = $("#needKeywords").val().trim().split(",");
                }
                //回显关键词小图标
                if (keyworldArray.length > 0) {

                    for (var i in keyworldArray) {
                        $("#keywordBox").append("<input  type='button' value='" + keyworldArray[i] + "\nx' class='layui-btn layui-btn-sm layui-bg-gray displayKeyword' onclick='GotoDeath(this)'/>");

                    }

                }

                //将问题问法list用空格拼成
                $("#questions").val(callbackData.howAskQuestions.join("\n"));


                //假如为单轮问答
                if (callbackData.answerType == "ONE_TO_ONE") {

                    //添加验证
                    oneToOneVerify();

                    //勾线上单句问答
                    $("#oneToOne").attr("checked", "checked");

                    //隐藏域储存标准答案
                    $("#ontoOneText").val(callbackData.oneToOneResult.join(","));

                    //显示一对一,OneToOneResult的答案
                    if ($("#ontoOneText").val() != "") {


                        var oneToOneResult = $("#ontoOneText").val().split(",");


                        for (var i in oneToOneResult) {

                            var onetoOneAnswer = "<div class='layui-form-item allAnswerDiv'>"
                                + "<label class='layui-form-label '>答案:</label>"
                                + "<div class='layui-input-block'>"
                                + "<textarea height: auto' class='allAnswers layui-textarea'  lay-verify='required'"
                                + " placeholder='请输入问题答案'   onblur='setanswerArray()'>"
                                + oneToOneResult[i]
                                + "</textarea>"
                                + "<input type='button' class='layui-btn layui-btn-sm layui-bg-gray allDelete'"
                                + "value='删除' onclick='deleterandfatherDiv(this)'/>"
                                + " </div> "
                                + "</div>";

                            $("#answerAfter").before(onetoOneAnswer);
                            $("#answerAfter").css("display", "block");

                            var index = parent.layer.getFrameIndex(window.name);
                            layer.iframeAuto(index);
                        }


                    }


                    //更新渲染
                    form.render();

                    //答后操作
                    $("#answerOperation").val(callbackData.afterAnswerOptionalType);


                    //答后操作显现
                    $("#answerAfter").css("display", "block");

                    //如果答后操作是跳到指定流程
                    if ($("#answerOperation").val() == "ASSIGN") {

                        $("#skipFlowId").val(callbackData.skipFlowId);


                        //调用方法再次发送ajax,取得流程的名字
                        findSelectParamName("/linkcall/learningAnalysis/selectPackageById",callbackData.skipFlowId, $("#skipFlowText"),"flowName");

                        $("#selectAnswerType").css("display", "block");
                    }
                    //更新渲染
                    form.render();

                } else {//回显的数据是多轮问答

                    //添加验证
                    sessionVerify();

                    //勾选多轮会话
                    $("#mutiSession").attr("checked", "checked");


                    //更新渲染
                    form.render();

                    //选取多轮会话的流程
                    $("#mutiSessionFlowId").val(callbackData.mutiSessionFlowId);

                    //调用方法再次发送ajax,取得流程的名字
                    findSelectParamName("/linkcall/learningAnalysis/selectSkipFlowById",callbackData.mutiSessionFlowId, $("#mutiSessionText"),"flowName");

                    $("#multiSelectAnswerType").css("display", "block");

                    //隐藏添加标准答案
                    $("#oneToOneanswer").css("display", "none");

                    //更新渲染
                    form.render();

                }

                //详情显现
                $("#needSelect").css("display", "block");
            }

        })


    }
};


//答案框点击删除,删除答案
function deleterandfatherDiv(needToDelete) {
    //删除DIV
    $(needToDelete).parent().parent().remove();

    //重新加载隐藏域数据
    setanswerArray();

    //假如一个答案没有了,答后操作隐藏
    if ($(".allAnswers").length == 0) {
        //隐藏答后操作
        $("#answerAfter").css("display", "none");
        //隐藏答后操作流程
        $("#selectAnswerType").css("display", "none");
        //恢复默认值
        $("#answerOperation").val("WAIT_CUSTOMER_ANSWER");
        //清空单句问答选择流程值
        $("#skipFlowId").val("");
        //这步重要,草他妈的layui,坑人
        form.render('select'); //刷新select选择框渲染
    }
}

//添加标准答案,弹出输入框
function addAnswer() {

    var onetoOneAnswer = "<div class='layui-form-item allAnswerDiv'>"
        + "<label class='layui-form-label '>答案:</label>"
        + "<div class='layui-input-block'>"
        + "<textarea height: auto' class='allAnswers layui-textarea' required lay-verify='required'"
        + " placeholder='请输入问题答案'  onblur='setanswerArray()'></textarea>"
        + "<input type='button' class='layui-btn layui-btn-sm layui-bg-gray allDelete'"
        + "value='删除' onclick='deleterandfatherDiv(this)'/>"
        + " </div> "
        + "</div>";


    $("#answerAfter").before(onetoOneAnswer);
    $("#answerAfter").css("display", "block");

}

/**
 * 每次答案框失去焦点,就重新循环遍历,刷新隐藏域的值
 */
function setanswerArray() {

    var answerArray = $(".allAnswers");

    var appendAnswer = "";


    answerArray.each(function (index, element) {

        var str = $(element).val();

        if (str != null && str.trim().length > 0) {

            appendAnswer += str.trim() + ",";
        }
    })

    $("#ontoOneText").val(appendAnswer.substring(0, appendAnswer.length - 1));

}


//日期
function getNowFormatDate() {
    var date = new Date();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if (hours >= 0 && hours <= 9) {
        hours = "0" + hours;
    }
    if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
    }
    var currentdate = "'" + date.getFullYear() + "-" + month + "-" + strDate
        + " " + hours + ":" + minutes + ":" + seconds + "'";
    return currentdate;
}
//移动选择的关键词
function moveSelect(source, target) {
    target.append(source);
    source.prop("selected",false)
}

//点击按钮,从自动分词的关键词select框中选到需要添加的关键词select框中
$("#moveToRight").click(function () {
    moveSelect($("#autoKeywords option:selected"), $("#addKeywords"));
});
$("#moveToLeft").click(function () {
    moveSelect($("#addKeywords option:selected"), $("#autoKeywords"));
});
$("#moveAllToRight").click(function () {
    moveSelect($("#autoKeywords option"), $("#addKeywords"));
});
$("#moveAllToLeft").click(function () {
    moveSelect($("#addKeywords option"), $("#autoKeywords"));
});

//对问法自动进行分词,提供推荐关键词给管理员选择
$("#autoAnalysis").click(function () {

    //获取所有问法
    var allQuestions = $("#questions").val();

    //用ajax去后台,调用接口进行分词
    $.ajax({
            type: "post",
            url: "/linkcall/knowledgeBase/autoAnalysis",
            data: {
                "allQuestions": allQuestions,
                "keywords": keyworldArray.join(",")
            },
            dataType: "json",
            success: function (callBack) {

                //1代表成功,0代表失败
                if("1"==callBack.code){

                   var dataList= callBack.data.keywords;

                    for (var i in dataList) {

                        $("#autoKeywords").append(" <option value='" + dataList[i] + "'>" + dataList[i] + "</option>");
                    }

                    var lay = layer.open({
                        type: 1,
                        title: "自动分词",
                        btn: ['保存', '取消'],
                        btn1: function (index, layero) {

                            //添加关键词
                            var keywords = $("#addKeywords option")

                            keywords.each(function (index, element) {
                                //存入关键词数组
                                keyworldArray.push($(element).val());
                                //添加关键词小图标
                                $("#keywordBox").append("<input  type='button' " +
                                    "value='" + $(element).val() + "\nx' " +
                                    "class='layui-btn layui-btn-sm layui-bg-gray displayKeyword' " +
                                    "onclick='GotoDeath(this)'/>");

                            })

                            //将数组转化为字符串,以逗号分隔,方便后台接受
                            $("#needKeywords").val(keyworldArray.join(","));
                            console.log($("#needKeywords").val());
                            //清空select框
                            $("#autoKeywords").empty();
                            $("#addKeywords").empty();

                            layer.close(index);

                        },
                        btn2: function (index, layero) {
                            //清空select框
                            $("#autoKeywords").empty();
                            $("#addKeywords").empty();

                            layer.close(index);

                        },
                        cancel:function (index, layero) {
                            //清空select框
                            $("#autoKeywords").empty();
                            $("#addKeywords").empty();

                        },
                        content: $("#selectKeyword")
                    })
                }else{

                    layer.msg('服务器正忙,请稍后重试');
                }
            }
        }
    );
})
//输入关键词,按回车结束
$("#addKeyword").keyup(function (event) {


    //键盘码为13,代表是出车
    if (event.keyCode == 13) {

        //取出内容
        var val = $("#addKeyword").val();

        var reg = /^[\u4E00-\u9FA5A-Za-z0-9]{1,20}$/;
        //判断一波
        if (reg.test(val)) {

            //将关键词存入可以keyword数组
            keyworldArray.push(val.trim());
            //<button class='layui-btn layui-btn-xs ' onclick='GotoDeath(this)'>"+val+ "x </button>&nbsp;

            //添加关键词小图标
            $("#keywordBox").append("<input  type='button' value='" + val + "\nx' class='layui-btn layui-btn-sm layui-bg-gray displayKeyword' onclick='GotoDeath(this)'/>");

            //将数组转化为字符串,以逗号分隔,方便后台接受
            $("#needKeywords").val(keyworldArray.join(","));
        } else {

            layer.msg("关键词含有非法字符或者长度超过20");
        }

        //清空输入框
        $("#addKeyword").val("");

    }


})


//用ajax的方式提交表单
//data为表单数据,url为提交路径
function insertDoc(saveData, postUrl, needClose) {

    //弹出loading层,友好提示
    var loading = layer.load(1, {
        shade: [0.1, '#fff'] //0.1透明度的白色背景
    });


    $.ajax({

            data: saveData,
            type: "post",
            url: postUrl,
            dataType: "json",
            success: function (callback) {

                layer.close(loading);

                layer.msg(callback.msg);

                if (callback.code == "1") {

                    if (needClose != null) {

                        parent.layer.close(needClose);//执行关闭

                        parent.layer.msg("保存成功");

                        parent.table.reload("newsListTable");

                        //parent.table.reload("newsListTable", {});

                    }


                }
            }

            ,
            error: function (callback) {

                layer.close(loading);

                parent.layer.msg("操作异常");
            }
        }
    )

}
//选择问题下拉框
$("#chooseKnowledgeText").autocomplete({
    minLength: 0,
    source: function (request, response) {
        // $("#belongUserId").val('')//清空输入框隐藏值
        $.ajax({
            url: 'loadKnowledgeBase',
            dataType: 'JSON',
            type: 'POST',
            data: {"text": $("#chooseKnowledgeText").val(),"packageId":$("#packageId").val()},
            success: function (data) {
                response($.map(data, function (item) {
                    return {
                        label: item.label,
                        value: item.value
                    }
                }));
            }
        });
    },
    focus: function (event, ui) {
        /* $(".queryText").val( ui.item.label );
         $("#queryText").val( ui.item.value );*/

        return false;
    },
    select: function (event, ui) {
        $("#chooseKnowledgeText").val(ui.item.label);
        $("#chooseKnowledgeBaseId").val(ui.item.value);
        changeKnowledgeBase(ui.item.label, ui.item.value);
        return false;
    }
});

/**jquery-ui 根据输入内容自动查询select下拉列表
 textDom: 显示文本的jquery对象
 valueDom:隐藏值得jquery对象
 url:搜索的url
 selectType:需要搜索的数据类型
 **/
function findAndSelect(textDom,valueDom,url,selectType) {

    textDom.autocomplete({
        minLength: 0,
        source: function (request, response) {
            // $("#belongUserId").val('')//清空输入框隐藏值
            $.ajax({
                url: url,
                dataType: 'JSON',
                type: 'POST',
                data: {"text": textDom.val(),"type":selectType,"packageId":$("#packageId").val()},
                success: function (data) {
                    response($.map(data, function (item) {
                        return {
                            label: item.label,
                            value: item.value
                        }
                    }));
                }
            });
        },
        focus: function (event, ui) {
            /* $(".queryText").val( ui.item.label );
             $("#queryText").val( ui.item.value );*/

            return false;
        },
        select: function (event, ui) {
            textDom.val(ui.item.label);
            valueDom.val(ui.item.value);
            return false;
        }
    });
}

//搜索并选择所属话术包
findAndSelect($("#packageText"),$("#packageId"),"/linkcall/knowledgeBase/selectPackage",null);

//搜索并选择主动会话流程
findAndSelect($("#skipFlowText"),$("#skipFlowId"),"/linkcall/knowledgeBase/loadSkipFlow","MAIN");

//搜索并选择多轮会话流程
findAndSelect($("#mutiSessionText"),$("#mutiSessionFlowId"),"/linkcall/knowledgeBase/loadSkipFlow","MultiWheel");



//ajax发送请求获取SkipFlow
function findSelectParamName(url,id,textInput,paramName) {


    //发送阿贾克斯
    $.ajax({
        type: "get",
        url: url,
        data: {id: id},
        dataType: "json",
        //async:false,
        success: function (callback) {

          switch (paramName){

              case "flowName": textInput.val(callback.flowName);break;

              case  "packageName" :  textInput.val(callback.packageName);break;

          }

        }

    })

}




//编辑问题和切换问题都需要清空数据
function resetToAdd() {
    //重置表单
    //$("#addKnowledgeBaseForm")[0].reset();
    //选择问题框要清空
    //$("#chooseKnowledgeBaseId").val("");
    // $("#chooseKnowledgeText").val("");
    //勾上一般问题
    $("#common").attr("checked", "checked")
    //title标题清空
    $("#title").val("");
    //所属话术包清空
    $("#originalPackageId").val("");
    $("#packageText").val("");
    //存储标准答案清空
    $("#ontoOneText").val("");
    //关键词隐藏域清空
    $("#needKeywords").val("");
    //关键词数组清空;
    keyworldArray = [];
    //關鍵詞輸入框清空
    $("#addKeyword").val("");
    //问法清空
    $("#howAskQuestions").val("");
    $("#questions").val("");
    //回答方式默认
    $("#oneToOne").attr("checked", "checked");
    //答后操作默认和隐藏
    $("#answerOperation").val("WAIT_CUSTOMER_ANSWER");
    $("#answerAfter").css("display", "none");
    //单句问答流程清空
    $("#skipFlowId").val("");
    $("#skipFlowText").val("");
    //隐藏
    $("#selectAnswerType").css("display", "none");
    //多轮问答流程清空
    $("#mutiSessionFlowId").val("");
    $("#mutiSessionText").val("");
    //隐藏
    $("#multiSelectAnswerType").css("display", "none");

    //清空关键词小图标和问题答案
    $(".displayKeyword").remove();
    $(".allAnswerDiv").remove();

    //重新渲染
    form.render();

}

//多轮会话下的验证
function sessionVerify() {

    //取消单轮答案验证
    $("#ontoOneText").attr("lay-verify", "")

    //取消单人选择流程验证
    $("#skipFlowText").attr("lay-verify", "");

    //取消单人问答答案框验证
    $(".allAnswers").attr("lay-verify", "");

    //添加多轮问答流程验证
    $("#mutiSessionText").attr("lay-verify", "mutiSessionFlowIdNotNull");
}

//单句问答验证
function oneToOneVerify() {

    //取消多轮问答流程验证
    $("#mutiSessionText").attr("lay-verify", "");
    //添加单轮问答验证
    $("#ontoOneText").attr("lay-verify", "mustNoNull")
    //添加单人答案框验证
    $(".allAnswers").attr("lay-verify", "required");
    //假如用户选择的是转跳到指定流程,添加验证
    if ($("#answerOperation").val() == "ASSIGN") {


        $("#skipFlowText").attr("lay-verify", "FlowIdNotNull");
    }

}

//检测title是否存在
function checkTitle(value) {
    //发送ajax请求到后台查找
    $.ajax({

        data: {"termTitle": value,"packageId":$("#packageId").val()},
        dataType: "json",
        type: "get",
        url: "/linkcall/knowledgeBase/selectByField",
        async: false,
        success: function (callBackData) {

            if (callBackData.total > 0) {

                existed = true;

            } else {

                existed = false;
            }
        }
    })
}
